package com.ftg.learn.chapter12;

import java.util.*;
import java.util.function.Function;

/**
 * 测试
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/2/13 下午4:01
 */
public class Q1 {

    /**
     * 给定一个数组根据你给的值进行返回
     * @param arr  数组
     * @param fn  表达式
     * @return
     */
    public Integer q21(int[] arr, Function<int[],Integer> fn){
        return fn.apply(arr);
    }

    public Set<Integer> q22(int[] arr, Function<int[], Set<Integer>> fn){
        return fn.apply(arr);
    }

    public static void main(String[] args) {
        Q1 q = new Q1();
        q.q21(new int[]{1, 23, 4, 4, 22, 34, 45, 11, 33},x->{
           int min = Integer.MIN_VALUE;
            for (int i : x) {
                min = Math.min(i,min);
            }
            return min;
        });

        q.q21(new int[]{1, 23, 4, 4, 22, 34, 45, 11, 33},x->{
            Arrays.sort(x);
            return x[0];
        });

        int sum1 = q.q21(new int[]{1, 23, 4, 4, 22, 34, 45, 11, 33},x->{
            Set<Integer> set = new TreeSet<>();

            for (int i : x) {
                set.add(i * 2);
            }

            int sum = 0;
            for (Integer integer : set) {
                sum += integer;
            }

            return sum;
        });


        Set<Integer> s = q.q22(new int[]{1, 23, 4, 4, 22, 34, 45, 11, 33},x->{
            //treeset
           Set<Integer> set = new TreeSet<>();

            for (int i : x) {
                set.add(i);
            }
           return set;
        });
        System.out.println(s);
        System.out.println(sum1);
    }

    public void q1 () {
        int[] nums = new int[10];
        int index = 0;
        while(index < nums.length){
            //产生随机数
            int num = (int)(Math.random() * 100 + 1);
            nums[index++] = num;
        }


        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        System.out.println(list);

        /**
         * asList 产生的是一个不可改变以的Arraylist实现类
         */
        List<Integer> list1 = Arrays.asList(1,2,3,4,5,6);
        System.out.println(list1);
    }

}
